from celery import Celery

# 一、加载django配置环境
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ending_framework_api.settings.dev")

broker = 'redis://127.0.0.1:6379/1'  # 消息中间件 redis
backend = 'redis://127.0.0.1:6379/2'  # 结果存储 redis
app = Celery(__name__, broker=broker, backend=backend,
             include=['celery_task.course_task', 'celery_task.home_task', 'celery_task.user_task'])

### 3 定时任务要写在这里
# 时区
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False

# 任务的定时配置
from datetime import timedelta
# from celery.schedules import crontab

# app.conf.beat_schedule = {
#     'send_sms': {
#         'task': 'celery_task.user_task.send_sms',
#         'schedule': timedelta(seconds=5),
#         # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
#         'args': ('1822344343', 8888),
#     },
#     'add_course': {
#         'task': 'celery_task.course_task.add_course',
#         # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
#         'schedule': crontab(hour=11, minute=38),  # 每天11点35，执行
#         'args': (),
#     }
# }
